<!DOCTYPE html>
<html>
<head>
<title> Seven Uploader Demo </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Seven Yu" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta charset="UTF-8" />
<script type="text/javascript" src="swfobject.js"></script>
<script >
<!--
var js4swf = {
    onStart: function(evt)
    {
        // 开始上传 (选择文件后自动开始)
        this.debug('start', evt);
        
        this.showMessage('开始上传: ' + evt.fileName);
        getById('frmMain').file.value = '';
        getById('frmMain').btnSubmit.disabled = 'disabled';
        
    },
    onCancel: function(evt)
    {
        // 上传取消事件
        this.debug('cancel', evt);
        
        this.showMessage('取消上传: ' + evt.fileName);
    },
    onComplete: function(evt)
    {
        // 上传完成事件 (包含文件信息和完成后返回数据(evt.data))
        this.debug('complete', evt);
        
        this.showMessage(evt.fileName + ' 上传完成!');
        getById('frmMain').btnSubmit.disabled = '';
        getById('frmMain').file.value = evt.fileName;
    },
    onWarn: function(evt)
    {
        // 报错事件 (evt.message)
        this.showMessage(evt.message);
        this.debug('warn', evt);
    },
    showMessage: function()
    {
        document.getElementById('output').innerHTML = arguments[0];
    },
    debug: function()
    {
        console && console.log(arguments);
    }
};

function getById(id)
{
    return document.getElementById(id);
}

function checkForm(frm)
{
    if(isEmpty(frm.title) || isEmpty(frm.desc))
    {
        js4swf.showMessage('请把资料填写完整.');
        return false;
    }
    
    if(isEmpty(frm.file))
    {
        js4swf.showMessage('上传尚未完成.');
        return false;
    }
    
    js4swf.showMessage('表单成功提交');
    return false;
}

function isEmpty(item)
{
    return trim(item.value) == ''
}

function trim(str)
{
    return str.replace('^\s+|\s+$/g', '');
}
//-->
</script>
</head>

<body>

<!--
按钮大小是 84 * 25
-->

<div id="output"></div>

<form id="frmMain" method="post" action="" onsubmit="return checkForm(this);" >

<!-- 嵌入 Flash -->
<div id="flashUploader"></div>
<script type="text/javascript">
var flashvars = { id: 1, jsobj: "js4swf", url: "../demo/upload.php", types: "图片文件:jpg,jpeg,png,gif;视频文件:mov,flv" };
var params = { allowScriptAccess: "allways" };
var attributes = { };
swfobject.embedSWF("../bin/flashUploader.swf", "flashUploader", "450", "45", "10.0.0", null, flashvars, params, attributes);
</script>

<!-- 表单内容 -->
<div>标题: <input type="text" name="title" /> </div>
<div>描述: <textarea name="desc" cols="40" rows="5" ></textarea></div>

<input type="hidden" name="file" />

<div><input type="submit" name="btnSubmit" disabled="disabled" /></div>

</form>

</body>
</html>
